$(document).ready(function(){

//  popup-add
$("#addQues").click(function(){

		debugger;
			$('#addQuestionnairePopup').slideDown("fast");
			
			});
		
	//弹窗关闭
	$('#closePopup').click(function(){
		//本行需要再 添加删除本页content的语句！！！
//		$('#showPopupIndex').hide();
		
		$('#addQuestionnairePopup').slideUp("fast");
	
//		$('body').css('overflow','auto');
	
	});
	
	
	$("#deleteButton").click(function(){
	var checkedCount=$('input[name="subBox"]:checked').length;
//	alert(checkedCount);
	if(checkedCount==0){
		$('#NoChecked').slideDown("fast");
	}
	
	else{
		$('#deleteQusPopup').slideDown("fast");
	}
			});
	
	//单个问卷删除
	$(".deleteQuestionnaireSingle").click(function(){
		var questionnaireId=$(this).children(".questionnaireIdCurrent").val();
		$('#deleteSingleQues').slideDown("fast");
		$("#sureSingleQues").click(function(){
//			alert("222222");
			window.location.href="deleteQuestionnaire.action?questionnaireId="+questionnaireId;
		});
		$("#cancelSingleQues").click(function(){
			$('#deleteSingleQues').slideUp("fast");
		});
		
	});
	
	//没选弹窗确定
	$('#noChosedClose').click(function(){
		$('#NoChecked').slideUp("fast");
	});	
	
	//弹窗关闭
	$('#cancel').click(function(){

		$('#deleteQusPopup').slideUp("fast");
	
		$('body').css('overflow','auto');
	
	});
	
//popup-edit
	$(".editQuestionnaireButton").click(function(){
		var questionnaireId=$(this).children(".questionnaireIdCurrent").val();
//		alert(questionnaireId);
		$('#editQuestionnairePopup').slideDown("fast");
		$.ajax({
			url:"toEditQuestionnaire.action?questionnaireId="+questionnaireId,
			success:function(data){
				var dataObject=JSON.parse(data);
				var questionnaireLast=dataObject["questionnaireLast"];
				var questionnaireDeadlineLast=dataObject["questionnaireDeadlineLast"];
				$("#questionnaireNameEdit").val(questionnaireLast.questionnaireName);
				$("#questionnaireDeadlineEdit").val(questionnaireDeadlineLast);
				var questionnaireStatusLast=questionnaireLast.questionnaireStatus;
//				alert("questionnaireStatusLast:"+questionnaireStatusLast);
				var questionnaireCategory=questionnaireLast.questionnaireCategory;
				switch (questionnaireStatusLast)
				{
				case true:
					$("#questionnaireStatusOpen").attr("selected","selected");
				  break;
				case false:
					$("#questionnaireStatusClosed").attr("selected","selected");
				  break;
				default:
					alert("状态错误！questionnaireStatus error！");
				}

				switch (questionnaireCategory)
				{
				case 1:
					$("#questionnaireCategory1").attr("selected","selected");
				  break;
				case 2:
					$("#questionnaireCategory2").attr("selected","selected");
				  break;
				case 3:
					$("#questionnaireCategory3").attr("selected","selected");
				  break;
				default:
					alert("种类错误！questionnaireCategory error！");
				}
				}
		});
			
	});
	$('#closeEditPopup').click(function(){
		$('#editQuestionnairePopup').slideUp("fast");
	});
	//全选功能
	$(function() {
        $("#checkAll").click(function() {
             $('input[name="subBox"]').attr("checked",this.checked); 
         });
         var $subBox=$("input[name='subBox']");
         $subBox.click(function(){
             $("#checkAll").attr("checked",$subBox.length == $("input[name='subBox']:checked").length ? true : false);
         });
	});
     //多选删除
         $("#sureDeleteButton").click(function(){
        	 $('#deleteQusPopup').slideUp("fast");
         var questionnaireIdList="";
         $('input[name="subBox"]:checked').each(function(){
        	 questionnaireIdList +=$(this).val()+",";
     		});
         $.ajax({
     		url:"deleteQuestionnaireMulti.action?questionnaireIdList=" + questionnaireIdList,
//     		 async:false,
//     		dataType:'json',
//     		scriptCharset: 'utf-8',
//     		contentType:'application/x-www-form-urlencoded; charset=UTF-8',
     		success:function(data){
     			window.location.href="fusionSearchQuestionnaire.action?number=1&questionnaireName=&questionnaireStatus=2&questionnaireCategory=0&timeStart=&timeEnd=";
     		}
         });
         });
         
       /*//分割线=======单搜索======================================================================================
//         $(document).ready(function(){
        		var searchByStatus=$("#status").val();
        		var searchByCategory=$("#category").val();
        		var searchBySearchType=$("#searchType").val();
        		 alert("quesStatus:"+typeof(quesStatus));
        		alert("quesCategory:"+typeof(quesCategory)); 
        		//搜索功能保持之前的状态
        		switch (searchByStatus)
        		{
        		case '1':
        			$("#status1").attr("selected","selected");
        		  break;
        		case '0':
        			$("#status0").attr("selected","selected");
        		  break;
        		 default:
        			alert("状态错误！searchByStatus error！"); 
        		}
                //搜索功能保持之前的种类
        		switch (searchByCategory)
        		{
        		case '1':
        			$("#category1").attr("selected","selected");
        		  break;
        		case '2':
        			$("#category2").attr("selected","selected");
        		  break;
        		case '3':
        			$("#category3").attr("selected","selected");
        		  break;
        		 default:
        			alert("种类错误！searchByCategory error！"); 
        		}
        		//搜索功能保持之前搜索类型
        		switch (searchBySearchType)
        		{
        		case '1':
        			$("#searchType1").attr("selected","selected");
        		  break;
        		case '2':
        			$("#searchType2").attr("selected","selected");
        		  break;
        		case '3':
        			$("#searchType3").attr("selected","selected");
        		  break;
        		case '4':
        			$("#searchType4").attr("selected","selected");
        		  break;
        		case '5':
        			$("#searchType5").attr("selected","selected");
        		  break;
        		case '6':
        			$("#searchType6").attr("selected","selected");
        		  break;
        		case '7':
        			$("#searchType7").attr("selected","selected");
        		  break;
        		case '0':
        			$("#searchType0").attr("selected","selected");
        		  break;
        		 default:
        			alert("种类错误！searchBySearchType error！"); 
        		}
        		
        	 $("#searchTypeSelection").click(function(){   
        	setInterval(changDisplay,200);
        	
        	//根据搜索类型显示相应的输入框
        		 function changDisplay(){
        	var select=$("#searchTypeSelection").val();

        	switch(select) 
        	{ 
        	case '0': 
        		$("#searchWords").css("display","inline");
        		$("#date").css("display","none");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","none");
        		break; 
        	case '1': 
        		$("#searchWords").css("display","inline");
        		$("#date").css("display","none");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","none");
        		break;
        	case '2':
        		$("#searchWords").css("display","none");
        		$("#date").css("display","none");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","inline");
        		break; 
        	case '3': 
        		$("#searchWords").css("display","none");
        		$("#date").css("display","none");
        		$("#categorylist").css("display","inline");
        		$("#statuslist").css("display","none");
        		break; 
        	case '4': 
        		$("#searchWords").css("display","inline");
        		$("#date").css("display","none");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","none");
        		break; 
        	case '5': 
        		$("#searchWords").css("display","inline");
        		$("#date").css("display","none");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","none");
        		break; 
        	case '6': 
        		$("#searchWords").css("display","none");
        		$("#date").css("display","inline");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","none");
        		break;
        	case '7': 
        		$("#searchWords").css("display","none");
        		$("#date").css("display","inline");
        		$("#categorylist").css("display","none");
        		$("#statuslist").css("display","none");
        		break;
        	default: 
        	alert("类型不对哦哦哦哦");
        	} 
        	}
//        	});
*/
         //融合搜索======start========================================
         var questionnaireStatus=$("#questionnaireStatusHidden").val();
		 var questionnaireCategory=$("#questionnaireCategoryHidden").val();
//		 alert("questionnaireStatus:"+questionnaireStatus);
		 /* alert("quesStatus:"+typeof(quesStatus));
 		alert("quesCategory:"+typeof(quesCategory)); */
		 //搜索结果保持之前的状态选择
		 switch (questionnaireStatus)
		 {
		 case '1':
			 $("#status1").attr("selected","selected");
			 break;
		 case '2':
			 $("#status2").attr("selected","selected");
			 break;
		 case '0':
			 $("#status0").attr("selected","selected");
			 break;
			 /* default:
 			alert("状态错误！searchByStatus error！"); */
		 }
		 //搜索结果保持之前的种类选择
		 switch (questionnaireCategory)
		 {
		 case '1':
			 $("#category1").attr("selected","selected");
			 break;
		 case '2':
			 $("#category2").attr("selected","selected");
			 break;
		 case '3':
			 $("#category3").attr("selected","selected");
			 break;
		 case '0':
			 $("#category0").attr("selected","selected");
			 break;
			 /* default:
 			alert("种类错误！searchByCategory error！"); */
		 }
       //融合搜索======end========================================
         });